home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / diskBoot.OpenProm / sun4c.md / start.s < prev   
Encoding:
Text File  |  1991-09-01  |  2.3 KB  |  96 lines

  1. !
  2. ! The following variable MUST be the first thing in this
  3. ! file, as its position marks the beginning of small data
  4. !
  5.     .seg    "data"
  6.     .global    _environ        ! first symbol in sdata        
  7. _environ:
  8.     .word    0
  9.  
  10.     .seg    "text"
  11.     .align    4
  12. !
  13. ! Startup code for standalone system
  14. !
  15. WINDOWSIZE = (16 * 4)
  16.  
  17.     .global    _end
  18.     .global    _edata
  19.     .global    _main
  20.     .global    __exit
  21.     .global    _Boot_Transfer
  22.     .global _romVectorPtr
  23.     .global    start
  24. start:
  25.     save    %sp, -WINDOWSIZE, %sp    ! get a new window, leave room for args
  26.     call    1f            ! get the current pc into o7
  27.     nop                ! (where entry is currently located)
  28. 1:
  29.     mov    %o7, %o0        ! save for later
  30.     sub    %o0, 4, %o0        ! point to first byte of prog
  31.     set    start+4,%o6        ! address of call instruction - above 
  32.     cmp    %o6, %o7        ! are they the same
  33.     be    go
  34.     nop
  35.     set    _edata+4, %o2        ! end of program, inclusive, except bss
  36.     set    start, %o1        ! beginning of program
  37.     sub    %o2, %o1, %o2        ! size of program
  38.     !
  39.     ! copy program where it belongs
  40.     !
  41. 2:
  42.     ld    [%o0], %o3        ! read a word
  43.     add    %o0, 4, %o0            ! point to next src word
  44.     st    %o3, [%o1]        ! write a word
  45.     subcc    %o2,4, %o2        ! check if done
  46.     bge    2b            ! if not loop
  47.     add    %o1, 4, %o1        ! delay slot, point to next dest word
  48.     
  49.     set    go, %g1        ! now that it is relocated, jump to it
  50.     jmp    %g1
  51.     nop
  52.     ! program is now relocated
  53. go:
  54.     ! we should turn on cache at least by now
  55.     set    _romVectorPtr, %o2
  56.     st    %i0, [%o2]
  57.     set    _end+4, %o2        ! end of bss
  58.     set    _edata, %o0        ! beginning of bss
  59.     sub    %o2, %o0, %o2        ! size of bss
  60.     ! zero the bss
  61. 1:
  62.     subcc    %o2,1,%o2            ! loop to zero bss
  63.     st    %g0, [%o0]
  64.     bnz    1b
  65.     add    %o0, 4, %o0
  66.  
  67.     ! general startup code
  68.     set    (_environ+0x1000), %g7    ! 1st global register (etext + 4K)
  69.     set    0x2000, %g6        ! 8k
  70.     add    %g7, %g6, %g6        ! 2nd global register (1st global + 8K)
  71.     ld    [%sp + WINDOWSIZE], %o0    ! argc
  72.     add    %sp, WINDOWSIZE + 4, %o1! argv
  73.     sll    %o0, 2, %o2        ! argc * sizeof (int)
  74.     add    %o2, 4, %o2        ! skip 0 at end of arg ptrs
  75.     add    %o1, %o2, %o2        ! environ ptr
  76.     call    _main
  77.     st    %o2, [%g7 + -0x1000]    ! store 1st word of sdata %ad(_environ)
  78.     nop
  79. #ifdef notdef
  80.     call    _exit            ! exit(0)
  81. #endif
  82.     mov    0, %o0            ! delay slot
  83. __exit:
  84.     ret                ! ret to prom
  85.     restore
  86.  
  87. _Boot_Transfer:
  88.         mov     %o0, %g1
  89.         mov     %o1, %i0                ! preserve some arguments
  90.         mov     %o2, %i1                ! preserve some arguments
  91.         jmp     %g1
  92.         restore
  93.  
  94. _romVectorPtr:
  95.     .word    0
  96.